package karaoke.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;

import karaoke.excepcion.DAOExcepcion;
import karaoke.modelo.Comprobante;
import karaoke.util.ConexionBD;
import karaoke.dao.BaseDAO;

public class ComprobanteDAO {
	
	
	public Comprobante insertar(Comprobante vo) throws DAOExcepcion {
		
	
		String query = "insert into Comprobante(fecComprobante,horaComprobante,TipoDoc_idTipoDoc) values (?,?,?)";
		Connection con = null;
		PreparedStatement stmt = null;
		ResultSet rs = null;
		try {
			con = ConexionBD.obtenerConexion();
			stmt = con.prepareStatement(query);
//			stmt.setDate(1,vo.getFecha());
			stmt.setInt(2,vo.getNrocomprobante());	
			stmt.setString(3,vo.getHora());
			

			
			int i = stmt.executeUpdate();
			if (i != 1) {
				throw new SQLException("No se pudo insertar");
			}
			
	//*		String id = 0;
	//		query = "select last_insert_id()";
	//		stmt = con.prepareStatement(query);
	//		rs = stmt.executeQuery();
	//		if (rs.next()) {
	//			id = rs.getString(1); 
	//		}
	//		vo.setNrocomprobante(id);

		} catch (SQLException e) {
			System.err.println(e.getMessage());
			throw new DAOExcepcion(e.getMessage());
		} finally {
//			this.cerrarResultSet(rs);
//			this.cerrarStatement(stmt);
//			this.cerrarConexion(con);
		}
		return vo;
   }
}